
from pages.base_page import BasePage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class BusinessPage(BasePage):
    url = "/crm/index.php?m=business"
    result_locator = (By.XPATH, '/html/body/div[5]/div[2]')
    error_locator =(By.XPATH,"/html/body/div/form/fieldset/div[1]")
    # 选择第一个商机
    choose_first_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input')
    # 删除
    delete_locator = (By.ID, 'delete')
    # 查看
    check_locator = (By.LINK_TEXT, '查看')
    # 搜索
    field_locator = (By.ID, 'field')
    condition_locator = (By.ID, 'condition')
    search_locator = (By.ID, 'search')
    dosearch_locator = (By.ID, 'dosearch')
    recycle_locator = (By.CSS_SELECTOR,'body > div.container > p > a:nth-child(17)')
    searched_text_locator = (By.CSS_SELECTOR,'#form1 > table > tbody')

    def click_choose_first(self):
        """
        选择第一个
        """
        self.find_element(self.choose_first_locator).click()

    def click_delete(self):
        """
        点击删除
        """
        self.find_element(self.delete_locator).click()

    def click_check(self):
        """
        点击查看
        """
        self.find_element(self.check_locator).click()

    def select_field(self, field_text):
        """
        选择筛选条件
        """
        field_element = Select(self.find_element(self.field_locator))
        field_element.select_by_visible_text(field_text)

    def click_condition(self,condition):
        """
        选择包含框
        """
        self.find_element(self.condition_locator).send_keys(condition)


    def input_search(self,search):
        """
        输入搜索关键词
        """
        self.find_element(self.search_locator).send_keys(search)

    def click_dosearch(self):
        """
        点击搜索
        """
        self.find_element(self.dosearch_locator).click()

    def click_recycle(self):
        """
        点击回收站
        """
        self.find_element(self.recycle_locator).click()


    def get_searched_text(self):
        """
        获取搜索结果的文本
        """
        return self.find_element(self.searched_text_locator).text
#返回增删改查后的提示信息
    def get_result_tips(self):
        return self.find_element(self.result_locator).text

#返回弹窗文本信息
    def get_alert_text(self):
        return self.driver.switch_to.alert.text

#返回报错弹窗文本信息
    def get_error_text(self):
        return self.find_element(self.error_locator).text

